def get_valid_input(prompt, input_type=int, min_value=None, max_value=None):
    """获取有效输入"""
    while True:
        try:
            value = input_type(input(prompt))
            if min_value is not None and value < min_value:
                print(f"输入值不能小于 {min_value}，请重新输入！")
                continue
            if max_value is not None and value > max_value:
                print(f"输入值不能大于 {max_value}，请重新输入！")
                continue
            return value
        except ValueError:
            print("输入无效，请输入一个有效的数字！")